package com.xy.controller.admin.system;

import com.xy.api.model.dto.system.RoleDTO;
import com.xy.api.model.request.system.KeywordPageRequest;
import com.xy.api.model.response.R;
import com.xy.api.model.response.Rows;
import com.xy.api.service.system.IRoleService;
import com.xy.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/system/role")
public class RoleController extends BaseController {

    @Autowired
    private IRoleService roleService;

    @PostMapping("/list")
    public R queryRoleList(@RequestBody KeywordPageRequest request) {
        Rows<RoleDTO> rows = roleService.queryRoleList(request);
        return success(rows);
    }

    @PostMapping("/allList")
    public R queryAllRoleList() {
        Rows<RoleDTO> rows = roleService.queryAllRoleList();
        return success(rows);
    }

    @PostMapping("/detail")
    public R queryRoleDetail(@RequestBody RoleDTO request) {
        RoleDTO roleDetail = roleService.queryRoleDetail(request.getId());
        return success(roleDetail);
    }

    @PostMapping("/edit")
    public R editRole(@RequestBody RoleDTO request) {
        roleService.editRole(request);
        return success();
    }

    @PostMapping("/delete")
    public R deleteRole(@RequestBody RoleDTO request) {
        roleService.deleteRole(request.getId());
        return success();
    }
}
